package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.mapper.SysDictDataMapper;
import com.huike.clues.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    @Autowired
    private TbBusinessMapper tbBusinessMapper;
    @Autowired
    private SysDictDataMapper sysDictDataMapper;
    @Override
    public void insert(TbBusinessTrackRecord tbBusinessTrackRecord, TbBusiness tbBusiness) {
        //商机跟进表新增
        tbBusinessTrackRecordMapper.insert(tbBusinessTrackRecord);
        //商机表修改
        tbBusinessMapper.updateTbBusiness(tbBusiness);
    }
    /**
     * 查询商机跟进记录列表
     */
    @Override
    public List<TbBusinessTrackRecord> findListByBusinessId(Long id) {
        //1.查询商机跟进记录列表
        List<TbBusinessTrackRecord> list = tbBusinessTrackRecordMapper.findListByBusinessId(id);
        //2.将沟通重点通过字典转换为文字
        for (TbBusinessTrackRecord tbBusinessTrackRecord : list) {
            if (tbBusinessTrackRecord.getKeyItems() != null && tbBusinessTrackRecord.getKeyItems().length()>0) {
                String[] items=tbBusinessTrackRecord.getKeyItems().split(",");
                for (String item : items) {
                    String dictLabel = sysDictDataMapper.selectDictLabel("communication_point", item);
                    tbBusinessTrackRecord.getKeys().add(dictLabel);
                }
            }
        }
        return list;
    }
}
